/**
 * @typedef CreateStaffBody
 * @property {string} username.required - 用户名 - eg: admin
 * @property {string} password.required - 密码
 * @property {string} nickname - 昵称
 * @property {enum} gender - 员工性别 - eg: 0,1
 * @property {enum} status.required - 员工状态 0 禁用 1 启用 - eg: 0, 1
 * @property {number[]} roleIds - 角色列表
 * @property {string} avatar - 头像
 * @property {string} email - 邮箱
 * @property {string} tel - 手机号
 * @property {integer} age - 年龄
 */

/**
 * @typedef UpdateStaffBody
 * @property {integer} id - 员工标识
 * @property {string} nickname - 昵称
 * @property {enum} gender - 员工性别 - eg: 0, 1
 * @property {number[]} roleIds - 角色列表
 * @property {string} avatar - 头像
 * @property {string} email - 邮箱
 * @property {string} tel - 手机号
 * @property {integer} age - 年龄
 */

/**
 * @typedef DeleteStaffBody
 * @property {number[]} ids - 员工id列表
 */

/**
 * @typedef UpdateStatusBody
 * @property {integer} id - 员工标识
 * @property {enum} status.required - 员工状态 0 禁用 1 启用 - eg: 0, 1
 */

/**
 * @typedef ChangePasswordBody
 * @property {string} username.required - 用户名
 * @property {string} password.required - 新密码
 * @property {string} oldPassword.required - 旧密码
 */

const express = require('express')
const router = express.Router()
const auth = require('@/middleware/auth.middleware')
const staffController = require('@/controllers/staff.controller')

/**
 * 员工分页列表查询
 * @route GET /staff
 * @summary 员工分页列表查询
 * @group 员工管理
 * @param {string} pageNo.query.required
 * @param {string} pageSize.query.required
 * @param {string} searchKeywords.query
 * @param {string} email.query
 * @param {string} tel.query
 * @param {string} status.query
 * @returns {object} 200
 * @returns {Error}  default - Unexpected error
 * @access staff-manage-permission:btn:find
 * @security JWT
 */
router.get('/', auth(), staffController.findPage)

/**
 * 员工创建
 * @route POST /staff
 * @summary 员工创建
 * @group 员工管理
 * @param {CreateStaffBody.model} staffBody.body.required
 * @returns {object} 200
 * @returns {Error}  default - Unexpected error
 * @access staff-manage-permission:btn:add
 * @security JWT
 */
router.post('/', auth(), staffController.createStaff)

/**
 * 员工更新
 * @route PUT /staff
 * @summary 员工信息更新
 * @group 员工管理
 * @param {UpdateStaffBody.model} UpdateStaffBody.body.required
 * @returns {object} 200
 * @returns {Error}  default - Unexpected error
 * @access staff-manage-permission:btn:edit
 * @security JWT
 */
router.put('/', auth(), staffController.updateStaff)

/**
 * 员工状态更新
 * @route PUT /staff/updateStatus
 * @summary 员工状态更新
 * @group 员工管理
 * @param {UpdateStatusBody.model} UpdateStatusBody.body.required
 * @returns {object} 200
 * @returns {Error}  default - Unexpected error
 * @access staff-manage-permission:btn:edit
 * @security JWT
 */
router.put('/updateStatus', auth(), staffController.updateStatus)

/**
 * 员工批量删除
 * @route DELETE /staff
 * @summary 员工批量删除
 * @group 员工管理
 * @param {DeleteStaffBody.model} DeleteStaffBody.body.required
 * @returns {object} 200
 * @returns {Error}  default - Unexpected error
 * @access staff-manage-permission:btn:delete
 * @security JWT
 */
router.delete('/', auth(), staffController.batchDelete)

/**
 * 员工自身密码修改
 * @route POST /staff/change-password-self
 * @summary 员工自身密码修改
 * @group 员工管理
 * @param {ChangePasswordBody.model} ChangePasswordBody.body.required
 * @returns {object} 200
 * @returns {Error}  default - Unexpected error
 * @security JWT
 */
router.post('/change-password-self', auth(), (req, response) => {
  staffController.changePassword(req, response, true)
})

/**
 * 管理员修改员工密码
 * @route POST /staff/change-password
 * @summary 管理员修改员工密码
 * @group 员工管理
 * @param {ChangePasswordBody.model} ChangePasswordBody.body.required
 * @returns {object} 200
 * @returns {Error}  default - Unexpected error
 * @access staff-manage-permission:btn:change-password
 * @security JWT
 */
router.post('/change-password', auth(), (req, response) => {
  staffController.changePassword(req, response)
})

module.exports = router
